import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
import { CommonEntity, CommonStatus } from '~/common/entity/common.entity';
import { TenantEntity } from '~/modules/tenant/tenant.entity';
import { PointsGoodsExchangeEntity } from './points-goods-exchange/points-goods-exchange.entity';

@Entity({ name: 'ah_points_goods' })
@Index(['id'])
export class PointsGoodsEntity extends CommonEntity {
	// 商品名称、商品图片、商品描述、兑换所需积分、商品状态、排序值、是否已删除、租户ID、兑换次数
	@Column({ type: 'varchar', length: 255, comment: '商品名称' })
	name: string;

	@Column({ type: 'varchar', length: 255, comment: '商品图片' })
	image: string;

	@Column({ type: 'text', comment: '商品描述', nullable: true, default: null })
	description: string;

	@Column({ type: 'int', comment: '兑换所需积分' })
	price: number;

	@Column({ type: 'tinyint', width: 1, comment: '商品状态', default: CommonStatus.YES })
	status: CommonStatus;

	@Column({ type: 'int', comment: '排序值', default: 0, name: 'sort_order' })
	sortOrder: number;

	@Column({ type: 'tinyint', width: 1, comment: '是否已删除', name: 'is_deleted', default: CommonStatus.NO })
	isDeleted: CommonStatus;

	@Column({ type: 'int', comment: '兑换次数', name: 'exchange_count', default: 0 })
	exchangeCount: number;

	// 库存
	@Column({ type: 'int', comment: '库存', default: 0 })
	stock: number;

	@ManyToOne(() => TenantEntity, tenant => tenant.goods)
	@JoinColumn({ name: 'tenant_id' })
	tenant: TenantEntity;

	@OneToMany(() => PointsGoodsExchangeEntity, (exchanges) => exchanges.goods)
	goodsExchanges: PointsGoodsExchangeEntity[]
}
